//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.ComponentModel;
using GuidanceExplorer.Model;

namespace GuidanceExplorer.Services
{
    public enum GuidanceItemOperation { Create, Update, Delete }

    public enum AvailableLibrariesMode { AllowCreation, DoNotAllowCreation }

    /// <summary>
    /// Handles the interaction between the online storage and the offline files.
    /// </summary>
    public interface IOnlineStorageService
    {
        /// <summary>
        /// Return the available libraries in the storage.
        /// </summary>
        /// <returns></returns>
        LibraryCollection GetAvailableLibraries(AvailableLibrariesMode allowCreation);

        /// <summary>
        /// Obtains the guidance items and populates the library instance.
        /// </summary>
        void AddGuidanceItemsFileReferences(Services.IModelStorageService modelStorage, Library library);

        /// <summary>
        /// Publishes the guidance item to the online storage.
        /// </summary>
        /// <param name="guidanceItem"></param>
        bool PublishGuidanceItem(Library library, GuidanceItem guidanceItem, string content, GuidanceItemOperation operation, bool noWarning);

        /// <summary>
        /// Synchronize all the subscribed libraries
        /// </summary>
        void Syncronize(Services.IModelStorageService modelStorage, IHtmlRenderService htmlRender, bool showMessages, DoWorkEventArgs eventArgs);

        /// <summary>
        /// Creates a view in the online storage for the given library.
        /// </summary>
        /// <param name="subscribedLibrary"></param>
        /// <param name="view"></param>
        /// <returns></returns>
        string CreateOnlineView(string url, IModelStorageService modelService, Library subscribedLibrary, Model.View modelView, bool updateExistingView);

        /// <summary>
        /// Create or update a guidance type in the library
        /// </summary>
        /// <param name="gtype"></param>
        /// <param name="updateExistingType"></param>
        void CreateGuidanceType(string url, GuidanceType gtype, bool updateExistingType);

        /// <summary>
        /// True if the service is sync'ing with the online store
        /// </summary>
        /// <returns></returns>
        bool IsSynchronizing
        {
            get;
        }

        /// <summary>
        /// Add an item to the view.
        /// </summary>
        /// <param name="viewId"></param>
        /// <param name="gifr"></param>
        void AddGuidanceItemToView(string url, Guid viewId, GuidanceItemFileReferenceCollection guidanceItems);

        /// <summary>
        /// Creates a library in the online storage.
        /// </summary>
        /// <param name="library"></param>
        bool CreateLibrary(Library library, bool updateExisting);

        /// <summary>
        /// Return the id of the view within a library by its caption.
        /// </summary>
        /// <param name="subscribedLibrary"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        string GetViewIdByCaption(Library library, string viewCaption);

        /// <summary>
        /// Removes a view from the online store.
        /// </summary>
        /// <param name="view"></param>
        void RemoveView(View view);

        /// <summary>
        /// Removes a library from the online store.
        /// </summary>
        /// <param name="view"></param>
        void RemoveLibrary(Library library);
    }
}
